﻿using CoachingOrganizer.ClientInfrastructure.ServicesEntities.LocalStorage.Tools.EmotionsPack;
using CoachingOrganizer.Logic.Common;
using CoachingOrganizer.Logic.Models.Tools.EmotionsPack;
using CoachingOrganizer.Toolkit.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.Logic.Logic.Tools.EmotionsPack
{
    internal class EmotionTraceItemLogic
    {
        private readonly EmotionTraceItemModel _model;
        private readonly LogicExtender _logicExtender;
        private readonly EmotionTraceLogic _upperLogic;
        private readonly IEmotionTraceItemInfo _localData;
        
        public EmotionTraceItemModel Model
        {
            get { return _model; }
        } 

        public IEmotionTraceItemInfo LocalData
        {
            get { return _localData; }
        }

        public string EmotionName
        {
            get { return GetEmotionName(); }
        }

        public EmotionTraceItemLogic(EmotionTraceItemModel model, LogicExtender logicExtender, EmotionTraceLogic upperLogic, IEmotionTraceItemInfo localData)
        {
            _model = model;
            _logicExtender = logicExtender;
            _upperLogic = upperLogic;
            _localData = localData;
            model.RemoveDelegate = Remove;
            model.SaveDelegate = Save;
            model.GetEmotionNameDelegate = GetEmotionName;
        }

        private ActionResult Remove()
        {
            return _upperLogic.RemoveTraceItem(this);
        }

        private ActionResult Save()
        {
            _localData.TraceItemName = _model.TraceItemName;
            _localData.TracePicture = _model.TracePicture;
            return _localData.Save();
        }

        private string GetEmotionName()
        {
            return _upperLogic.Model.EmotionName;
        }
    }
}
